package cn.wolfcode.trip.base.domain;


import cn.wolfcode.trip.base.util.JSONUtil;
import com.alibaba.druid.support.json.JSONUtils;
import lombok.*;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Region extends BaseDomain{

    public static final Integer STATE_NOMAL = 0; //普通
    public static final Integer STATE_COMMEND = 1; //推荐

    private String name;

    private Region parent;  //父级区域

    private Integer state=STATE_NOMAL;


    //json字符串
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("state", state);
        if (parent!=null){
            map.put("parentId", parent.id);
            map.put("parentName", parent.name);
        }
        return JSONUtil.toJSONString(map);
    }

    //{id:xx,text: "全部区域",tags: ['4'],nodes: []}
    public Map<String,Object> getTreeview() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        map.put("lazyLoad", true);
        if (state==STATE_COMMEND){
            map.put("tags", new String[]{"推荐"});
        }
        return map;
    }
}